
import {
  getSysHospitalGetList,
  getDepAreaList,
  getCheckRoomList,
  getModalityList,
  getModalityTypeList,
  getlistbymodalityaddress,
  getDepList,
  getBigPartList,
  getHisCheckroomgetSmallpartlist,
  getItemGroupList,
  getItemList,
  getSysUserGetList,
  getDeptList,
  getRoleList,
  // getHisRegisterpartGetitempropertylist,
  getcheckroomgetlistbyareano,
  getcheckroomgetlistbynursestation,
  getCheckGroupList,
  getlistbyexamtype,
  getlistbyareaname
} from '@/api/api.js'
import { Options } from '@/utils/constant'
export default {
  data() {
    return {
      mx_DICKEY: 'dic_'
    }
  },
  methods: {
    /**
     * 暴露出去的方法，其他函数，通过这个函数调起
     * @param {*} method 函数名，需要执行的函数名， 名称由 dic_ + typeName 拼接的为数据字典获取类型数据方法，其他的为本地或者对应接口获取数据
     * @param {*} params 接口参数
     * @returns []
     */
    mx_getDicMethod(method, params) {
      console.log('进入mx_getDicMethod')
      return new Promise(async resolve => {
        console.log('method', method)
        console.log('params', params)
        console.log('params.HospitalCode', params.HospitalCode)
        if (!params.HospitalCode) {
          this.$message.warning('请先选择医院')
          resolve([])
        } else {
          console.log('method', method)
          console.log('this.mx_DICKEY', this.mx_DICKEY)
          // console.log('print_method', this[`mx_${method}`])
          console.log('print_method_name', `mx_${method}`)
          if (method.indexOf(this.mx_DICKEY) >= 0) {
            // 判断是否为数据字典维护的类型数据
            const opt = await this.mx_getDic(method, params)
            console.log('==opt1==', opt)
            resolve(opt)
          } else if (this[`mx_${method}`]) {
            console.log('method', method)
            const opt = await this[`mx_${method}`](params)
            // console.log('==opt2==', opt)
            resolve(opt)
          } else {
            console.log('else no request')
            resolve([])
          }
        }
      })
    },
    // 获取数据字典类型数据
    mx_getDic(type, params) {
      console.log('进入mx_getDic')
      console.log('type', type)
      console.log('params', params)
      return new Promise(async resolve => {
        const p = { ...params }
        p.type = type.replace(this.mx_DICKEY, '')
        console.log('p', p)
        let newDoc = ['申请医生', '申请病区', '申请科室']
        if (newDoc.indexOf(p.type) > -1) {
          p.Dep = ''
        }
        console.log('p', p)
        await getItemList(p).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const items = res.content.list.map(dic => { return dic.item })
            resolve(items)
          } else {
            resolve([])
          }
        })
      })
    },
    // 默认类型 不用判断
    mx_getDefault() {
      return []
    },
    mx_getSex() {
      return Options.genderItemOptions
    },
    mx_getPatType() {
      return Options.patientTypeItemOptions.map(item => item.label)
    },
    mx_getWeek() {
      return Options.weekOptions
    },
    mx_getYN() {
      return Options.yesnoItemOptions
    },
    mx_getExamMethod() {
      return Options.examMethodItemOptions
    },
    mx_getChanneWYYY() {
      return Options.channelOptions.WYYY
    },
    mx_getChanneLCYY() {
      return Options.channelOptions.LCYY
    },
    mx_getChanneVIP() {
      return Options.channelOptions.VIP
    },
    mx_getModalityAddress(params) {
      return new Promise(async resolve => {
        await getlistbymodalityaddress({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getSeasonal() {
      return Options.seasonal
    },
    mx_getHospital(params) {
      return new Promise(async resolve => {
        await getSysHospitalGetList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            let hospData = res.content.list
            hospData = hospData.map(hosp => { return { value: hosp.code, label: hosp.name } })
            resolve(hospData)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getCheckClass(params) {
      return new Promise(async resolve => {
        await getItemGroupList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getDepArea(params) {
      return new Promise(async resolve => {
        await getDepAreaList({ ...params }).then(res => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getBigPart(params) {
      return new Promise(async resolve => {
        await getBigPartList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getSmallPart(params) {
      return new Promise(async resolve => {
        await getHisCheckroomgetSmallpartlist({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getDep(params) {
      return new Promise(async resolve => {
        await getDepList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getCheckRoom(params) {
      return new Promise(async resolve => {
        await getCheckRoomList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getModality(params) {
      return new Promise(async resolve => {
        await getModalityList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getModalityType(params) {
      return new Promise(async resolve => {
        await getModalityTypeList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    mx_getUser(params) {
      return new Promise(async resolve => {
        await getSysUserGetList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const userList = res.content.list.map(item => item.userName)
            // 返回医生姓名列表
            resolve(userList)
          } else {
            resolve([])
          }
        })
      })
    },
    // 项目属性列表
    mx_getItemproperty(params) {
      return new Promise(async resolve => {
        // await getHisRegisterpartGetitempropertylist({ ...params }).then((res) => {
        //   if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
        //     const Itemproperty = res.content.list
        //     // 返回医生姓名列表
        //     resolve(Itemproperty)
        //   } else {
        //     resolve([])
        //   }
        // })
        await getItemGroupList({ ...params, type: '项目属性' }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            resolve(res.content.list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 院区代码列表
    mx_getListbyareano(params) {
      return new Promise(async resolve => {
        await getcheckroomgetlistbyareano({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const listbyareano = res.content.list
            // 返回院区代码列表
            resolve(listbyareano)
          } else {
            resolve([])
          }
        })
      })
    },
    // 护士站列表
    mx_getListbynursestation(params) {
      return new Promise(async resolve => {
        await getcheckroomgetlistbynursestation({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const listbyareano = res.content.list
            // 返回院区代码列表
            resolve(listbyareano)
          } else {
            resolve([])
          }
        })
      })
    },
    // 检查分组列表
    mx_getCheckgrouplist(params) {
      return new Promise(async resolve => {
        await getCheckGroupList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const listbyareano = res.content.list
            // 返回院区代码列表
            resolve(listbyareano)
          } else {
            resolve([])
          }
        })
      })
    },
    // 获取科室列表
    mx_getDeptList(params) {
      return new Promise(async resolve => {
        await getDeptList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list.map(item => item.departmentName)
            // 返回科室列表
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 获取角色列表mx_getRolelist
    mx_getRolelist(params) {
      return new Promise(async resolve => {
        await getRoleList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list
            // 返回角色列表
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 获取院区名称mx_getlistbyareaname
    mx_getlistbyareaname(params) {
      return new Promise(async resolve => {
        await getlistbyareaname({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list
            // 返回院区名称
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 获取检查类型mx_getlistbyexamtype
    mx_getlistbyexamtype(params) {
      return new Promise(async resolve => {
        await getlistbyexamtype({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list.map(item => item.roleName)
            // 返回检查类型
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 申请医生
    mx_getApplyDoctorList(params) {
      return new Promise(async resolve => {
        await getItemList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list.map(item => item.item)
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 申请科室
    mx_getApplySqdepList(params) {
      return new Promise(async resolve => {
        await getItemList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list.map(item => item.item)
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    },
    // 申请病区
    mx_getApplyWardnoList(params) {
      return new Promise(async resolve => {
        await getItemList({ ...params }).then((res) => {
          if (res && res.code === 10000 && res.content.list && res.content.list.length !== 0) {
            const list = res.content.list.map(item => item.item)
            console.log('申请病区list', list)
            resolve(list)
          } else {
            resolve([])
          }
        })
      })
    }
  }
}
